<template>
  <div>
    <!-- 搜索 -->
    <!-- 技术报告查询 - 维修工单选择 -->
    <TopFilter :list="topFilterInit" :cols="2" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"      @resetChange="resetHandle"></TopFilter>
    <BaseDialog :visible.sync="visible" :title="'车型选择'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Vehicle @close="close" @save="save"></Vehicle>
    </BaseDialog>
    <!--  服务中心选择 -->
    <BaseDialog :visible.sync="selectDelearFlag" title="服务中心选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DealerList @close="Delearclose" @save="Delearsave" selectionType="multiple" />
    </BaseDialog>
    <!-- table -->
    <FilterTable height="auto" selectionType="single" ref="table" :columns="columns" :fetchapi="fetchapi" :params="fetchParams" :dataSource="dataList" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange"> </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">添加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
  import { getSpList } from '@/api/claim/factory/ClaimQueryFactory/index';
  import Vehicle from '@/pages/claimDemage/tools/ModelVehicle.vue';
  import moment from "moment";
  import {  getAppId } from '@/assets/js/auth';
  import { dictionary } from '@/utils/dictMixin';
  import DealerList from '@/pages/claimDemage/tools/DealerList.vue';

export default {
  mixins: [dictionary],
  components: {
    Vehicle,
    DealerList
  },
  data() {
    return {
      // single: true,
      single: false,
      // 非多个禁用
      multiple: true,
      dealerList: [],
      selectDelearFlag: false,
      dealerCompanyCode: [],
      dealerData: [],
      selectDealerData: [],
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchapi:getSpList,
      // fetchApi: getUser,
      fetchParams: {
        claimStatus:55131008,cbFlag:1,xhrAbort: true
      }, //ipa 接口
      selectedRows: [] //选中经销商
    };
  },
  created() {

  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'SELECT',
          label: '服务中心',
          render: (p) => {
            return (
              <div>
                <el-select v-model={this.selectDealerData} disabled={true} multiple placeholder="请选择">
                  {this.dealerData.map((item) => (
                    <el-option key={item.dealerCode} label={item.dealerShortname} value={item.dealerCompanyCode} />
                  ))}
                </el-select>
                <multiuse-button style="position: absolute;right: 0;height:100%" icon="el-icon-search" onClick={() => this.selectDelearFlag = true} />
              </div>
            );
          },
          onChange: val => {
            console.log(val)
          }
        },
        { type: 'INPUT', label: '服务中心名称', fieldName: 'dealerName', placeholder: '请输入', initialValue: '' },

        { type: 'INPUT', label: '索赔单号', fieldName: 'claimNo', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '维修工单号', fieldName: 'roNo', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '索赔单状态', fieldName: 'claimStatus', placeholder: '请选择', initialValue: '', itemList: this.createDictList('5513', [55131001,55131002,55131003,55131004,55131005, 55131006,55131007]) },
        { type: 'INPUT', label: '主损件名称', fieldName: 'startTe', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '主损件代码', fieldName: 'startTim', placeholder: '请输入', initialValue: '' },

        { type: 'SELECT', label: '索赔类型', fieldName: 'cmsClaimType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('5510',[]) },
        { type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入', initialValue: '' },
        // {
        //   type: 'INPUT',
        //   label: '车型',
        //   fieldName: 'modelCode',
        //   placeholder: '请输入',
        //   initialValue: '',
        //   unitRender: p => {
        //     return (
        //       <div>
        //       <multiuse-button icon="el-icon-search" onClick={() => this.chooseOrderNo()} />
        //     </div>
        //   );
        //   }
        // },
        { type: 'INPUT', label: '车牌号', fieldName: 'vhlPlate', placeholder: '请输入', initialValue: '' },
        {
          type: 'RANGE_DATE',
          label: '提交日期',
          fieldName: 'beginSubmitAt|endSubmitAt',
          placeholder: '请输入',
          initialValue: [
            moment(new Date()).subtract(1,'months')
              .format('YYYY-MM-DD'),
            moment(new Date())
              .format('YYYY-MM-DD')
          ],
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }]
        },
      ];
    },
    resetHandle(val) {
      this.dealerData = [];
      this.selectDealerData = [];
      this.fetchParams = Object.assign({}, this.fetchParams, val, { claimStatus:55131008,dealerCompanyCode: null }, { xhrAbort: false });
    },
    //搜索获取数据
    changeHandle(val) {
      if (!val.beginSubmitAt) {
        this.$notify.warning({ title: '提示信息', message: '提交开始日期不可为空！' });
        return;
      }
      if (!val.endSubmitAt) {
        this.$notify.warning({ title: '提示信息', message: '提交结束日期不可为空！' });
        return;
      }
      val.beginSubmitAt = this.topFilterInit.find(x => x.fieldName == 'beginSubmitAt|endSubmitAt').initialValue[0];
      val.endSubmitAt = this.topFilterInit.find(x => x.fieldName == 'beginSubmitAt|endSubmitAt').initialValue[1];
      if(val.beginSubmitAt) {
        val.beginSubmitAt = moment(val.beginSubmitAt).format('YYYY-MM-DD HH:mm:ss');
      }
      if(val.endSubmitAt) {
        val.endSubmitAt =  moment(val.endSubmitAt).format('YYYY-MM-DD HH:mm:ss');
      }
      this.fetchParams = Object.assign({}, this.fetchParams, val, { claimStatus:55131008,cbFlag:1,xhrAbort: false,dealerCode: this.searchDealerCode, dealerCompanyCode: this.selectDealerData.length ? this.selectDealerData : null });

      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '服务中心代码', dataIndex: 'dealerCode', sorter: true },
        { title: '服务中心名称', dataIndex: 'dealerName', sorter: true },
        { title: '索赔单状态', dataIndex: 'statusStr', sorter: true },
        { title: '索赔单号', dataIndex: 'claimNo', sorter: true },
        { title: '索赔类型', dataIndex: 'cmsClaimTypeStr', sorter: true },
        { title: '预授权单号', dataIndex: 'authNo', sorter: true },
        { title: '维修工单号', dataIndex: 'roNo', sorter: true },
        { title: 'VIN', dataIndex: 'vin', sorter: true },
        { title: '车牌号', dataIndex: 'licenseNo', sorter: true },
        { title: '车型名称', dataIndex: 'modelName', sorter: true },
        { title: '主损件代码', dataIndex: 'partCode', sorter: true },
        { title: '主损件名称', dataIndex: 'partName', sorter: true },
        //{ title: '供应商', dataIndex: 'supName', sorter: true },
        { title: '行驶里程', dataIndex: 'driveMile', sorter: true },
        { title: '故障现象代码', dataIndex: 'faultCode', sorter: true },
        { title: '故障现象名称', dataIndex: 'faultName', sorter: true },
        { title: '故障原因代码', dataIndex: 'frCode', sorter: true },
        { title: '故障原因名称', dataIndex: 'frName', sorter: true },
        { title: '驳回次数', dataIndex: 'channelNum', sorter: true },
        { title: '索赔金额', dataIndex: 'sumAmount', sorter: true },
        { title: '工时费', dataIndex: 'labourAmount', sorter: true },
        { title: '配件费', dataIndex: 'partAmount', sorter: true },
        { title: '附加费用', dataIndex: 'addAmount', sorter: true },
        { title: '保修起始日期', dataIndex: 'repairBeginDate', sorter: true },
        { title: '保修截止日期', dataIndex: 'repairEndDate', sorter: true },
        { title: '生产日期', dataIndex: 'prodDate', sorter: true },
        { title: '销售日期', dataIndex: 'saleDate', sorter: true },
        { title: '维修日期', dataIndex: 'serviceBeginDate', sorter: true },
        { title: '申请时间', dataIndex: 'applyAt', sorter: true },
        { title: '申请人', dataIndex: 'applyName', sorter: true },
        { title: '审核时间', dataIndex: 'checkAt', sorter: true },
        { title: '审核人', dataIndex: 'checkBy', sorter: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //服务中心选择页面
    SelectDelear() {
      this.selectDelearFlag = true;
    }, //关闭
    Delearclose() {
      this.selectDelearFlag = false;
    },
    //服务中心选择保存
    Delearsave(obj) {
      console.log('选择数据传递', obj);
      this.dealerData = obj;
      this.selectDealerData = [];
      obj.forEach(item => {
        this.selectDealerData.push(item.dealerCompanyCode);
      });
      this.selectDelearFlag = false;
    },
    //保存
    saveDialog() {
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    },
    close() {
      this.visible = false;
    },
    save(obj) {
      this.topFilterInit.find(x => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
      this.visible = false;
    },
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
